package MyFitnessPlate.TestApplication;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;

public class TestApplicationActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        
        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Reusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab
        
        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, HomeActivity.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("home").setIndicator("home", 
                          res.getDrawable(R.drawable.tab_home))
                      .setContent(intent);
        tabHost.addTab(spec);

        // Do the same for the other tabs
        intent = new Intent().setClass(this, FoodActivity.class);
        spec = tabHost.newTabSpec("food").setIndicator("food",
                          res.getDrawable(R.drawable.tab_food))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, ExerciseActivity.class);
        spec = tabHost.newTabSpec("exercise").setIndicator("exercise",
                          res.getDrawable(R.drawable.tab_exercise))
                      .setContent(intent);
        tabHost.addTab(spec);
        
        intent = new Intent().setClass(this, WeightActivity.class);
        spec = tabHost.newTabSpec("weight").setIndicator("weight",
                res.getDrawable(R.drawable.tab_weight))
            .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, GoalsActivity.class);
		spec = tabHost.newTabSpec("goals").setIndicator("goals",
				res.getDrawable(R.drawable.tab_goals))
				.setContent(intent);
		tabHost.addTab(spec);

        tabHost.setCurrentTab(0);
    }
    
    //This creates the menu for the application. Because this is the parent where everything
    // is located, this is the one that will hold the menu.
    public boolean onCreateOptionsMenu(Menu menu){
    	MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.application_menu, menu);
        return true;
    }
    
    //This gives commands for when the menu items are clicked.
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.logout:
            	Intent myIntent = new Intent("MyFitnessPlate.TestApplication.Splash.STARTINGPOINT");
				startActivity(myIntent);
				finish();
                return true;
            case R.id.exit:
                this.finish();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}